
class Login{
    constructor(){
        this.text=document.querySelector("input[type='text']")
        this.span=document.querySelector('.geshi')
        this.password=document.querySelector("input[type='password']")
        this.des=document.querySelector('.btn')
        this.Btn=document.querySelector('.Btn')

        // console.log(this.text,this.span,this.password,this.des,this.Btn)
        this.init()
    }
    init(){
        this.render()
    }
    render(){
      this.text.oninput=()=>{
          let telReg = /^1[3-9][0-9]{9}$/
          if(telReg.test(this.text.value)){
              this.span.innerHTML='手机格式正确'
              this.span.style.color='red'
          }else{
            this.span.innerHTML='手机格式错误'
            this.span.style.color='black'
          }
          
      }
      this.password.oninput=()=>{
          let tel1Reg =/^[a-z0-9_-]{3,16}$/
          if(tel1Reg.test(this.password.value)){
            this.des.innerHTML='密码正确'
            this.des.style.color='red'
        }else{
          this.des.innerHTML='密码错误'
          this.des.style.color='black'
        }
      }
      this.Btn.onclick=()=>{
        let username=this.text.value
        let password=this.password.value
        if(username == '' || password == ''){
          alert('手机号密码不能为空')
          return false
        }
        this.request(username,password)
    }
    }
    request(username,password){
        $.ajax({
            url: 'http://api.yuguoxy.com/api/member/login',
            type: 'post',
            data:{
                username,
                password
            }
        })
        .then(res=>{
            if(this.des.innerHTML=='密码格式错误'){
                return false
            }
            // console.log(res)
            if(res.resultCode == 1){
                alert('登录成功')
                    location.href='../index.html'
            }else{
                   !res.resultCode == 1
                    alert('不是会员请点击注册')
                    // location.href='../html/register.html'
                
            }
            
        })

    }

}
new Login